package Leetcode;

import java.util.ArrayList;
import java.util.List;

public class partitionLabels {
    public List<Integer> partitionLabels(String s) {
        int[] hash = new int[26];
        List<Integer> res = new ArrayList<>();
        char[] charArray = s.toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            hash[charArray[i] - 'a'] = i;
        }
        int index = 0;
        int last = -1;
        for (int i = 0; i < charArray.length; i++) {
            index = Math.max(index, hash[charArray[i] - 'a']);
            if (i == index){
                res.add(i - last);
                last = i;
            }
        }
        return res;
    }
}
